package com.hnevc.netfoodchoose;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {

    //定义handler消息处理者
    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what==101){
                //若是101信号，则跳转
                Intent intent=new Intent();
                intent.setClass(SplashActivity.this,
                        MainActivity.class);
                //启动intent，启动activity
                startActivity(intent);
                //关闭当前activity
                SplashActivity.this.finish();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        //获取图片控件
        ImageView imageView=(ImageView)findViewById(R.id.id_iv_splash);
        //获取补间动画
        Animation animation= AnimationUtils.loadAnimation(this,R.anim.scale_animation);
       //应用补间动画
        imageView.startAnimation(animation);

        new Thread(new Runnable() {
            @Override
            public void run() {
                int i=0;
                while(true){
                    if(i==4){
                        Message msg=new Message();
                        msg.what=101;
                        mHandler.sendMessage(msg);
                    }
                }
            }
        }).start();

    }

}
